package com.pro.controller;

import com.pro.pojo.JsDeptAuthority;
import com.pro.pojo.JsonData;
import com.pro.service.JsDeptAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author 祖铭泽
 * @Date 2021/11/19/0019
 * @description 部门权限表 控制层
 */
@Controller
@RequestMapping(value = "/JsDeptAuthority")
public class JsDeptAuthorityController {
    @Autowired
    private JsDeptAuthorityService jsDeptAuthorityService;
    //添加部门时将此部门拥有的权限添加到部门权限表
    @RequestMapping(value = "/addJsDeptAuthority")
    @ResponseBody
    public JsonData addJsDeptAuthority(JsDeptAuthority jsDeptAuthority){
        boolean addJsDeptAuthority = jsDeptAuthorityService.addJsDeptAuthority(jsDeptAuthority);
        return addJsDeptAuthority ? JsonData.buildSuccess(jsDeptAuthority) : JsonData.buildError("服务器出错了");
    }

    //根据部门id查询当前部门所有权限
    @RequestMapping(value = "/getAuthoritysByDeptId")
    @ResponseBody
    public JsonData getAuthoritysByDeptId(Integer deptId){
        List<JsDeptAuthority> authoritys = jsDeptAuthorityService.getAuthoritysByDeptId(deptId);
        return authoritys != null ? JsonData.buildSuccess(authoritys) : JsonData.buildError("服务器出错了");
    }
    //删除部门所拥有的权限
    @RequestMapping(value = "/delDeptAuthorityByDeptId")
    @ResponseBody
    public JsonData delDeptAuthorityByDeptId(Integer deptId){
        boolean delDeptAuthorityByDeptId = jsDeptAuthorityService.delDeptAuthorityByDeptId(deptId);
        return delDeptAuthorityByDeptId ? JsonData.buildSuccess("成功") : JsonData.buildError("服务器出错了");
    }


}
